#include <iostream>
#include <unistd.h>
using namespace std;

int Test1(){
  pid_t id = fork();
  if(id < 0)
  {
    //创建失败
    cerr << "fork" << endl;
    return 1;
  }
  else if(id == 0)
  {
    //子进程执行流
      cout << "I'm child process, ";
      cout << "pid:" << getpid() << " ";
      cout << "ppid:" << getppid() << endl;
      sleep(3);
    return 0;
  }
  else{
    //父进程执行流
    while(1)
    {
      cout << "I'm parent process, ";
      cout << "pid:" << getpid() << " ";
      cout << "ppid:" << getppid() << endl;
      sleep(1);
    }
    return 0;
  }
}

int Test2(){
  pid_t id = fork();
  if(id < 0)
  {
    //创建失败
    cerr << "fork" << endl;
    return 1;
  }
  else if(id == 0)
  {
    //子进程执行流
    while(1)
    {
      cout << "I'm child process, ";
      cout << "pid:" << getpid() << " ";
      cout << "ppid:" << getppid() << endl;
      sleep(1);
    }
    return 0;
  }
  else{
    //父进程执行流
      cout << "I'm parent process, ";
      cout << "pid:" << getpid() << " ";
      cout << "ppid:" << getppid() << endl;
      sleep(3);
    return 0;
  }
}

//进程优先级
int Test3(){
  while(1)
  {
    cout << "hello world!" <<endl;
    sleep(1);
  }
}

int main(){
  //return Test1();
  //Test2();
  Test3();
  return 0;
}
